package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_ProductImage;

import com.openbravo.bean.Product;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.ImageUtils;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.bean.ProductImage;

public class ProductImageDAO extends ModifiedLogDAO<ProductImage>{
   
	public ProductImageDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                   "PRODUCT_IMAGE",
                    new Field[]{
                new Field(I_ProductImage.ID, Datas.STRING, Formats.STRING),
                new Field(I_ProductImage.PRODUCT_ID, Datas.STRING, Formats.STRING,Product.class),
                new Field(I_ProductImage.NAME, Datas.STRING, Formats.STRING),
                new Field(I_ProductImage.IMAGE, Datas.IMAGE, Formats.NULL),
                new Field(I_ProductImage.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0}
        );
    }

	@Override
	public void writeInsertValues(DataWrite dp, ProductImage obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(2,obj.getProductId());
		dp.setString(3,obj.getM_Name());
		dp.setBytes(4, obj.getM_Image());
		dp.setTimestamp(5,obj.getLastModified());
		
	}

	@Override
	public Class getSuportClass() {
		return ProductImage.class;
	}

	@Override
	public ProductImage readValues(DataRead dr, ProductImage obj)
			throws BasicException {
		if(obj==null)
			obj=new ProductImage();
		obj.setId(dr.getString(1));
		obj.setProductId(dr.getString(2));
		obj.setM_Name(dr.getString(3));
		obj.setM_Image(dr.getBytes(4));
		obj.setLastModified(dr.getTimestamp(5));
		return obj;
	}
}
